﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Development.Network.MsgHandle
{
    /// <summary>
    ///消息处理基类
    /// </summary>
    public class MsgHandle
    {
        /// <summary>
        /// 消息起始id
        /// </summary>
        protected int _msgStartId;
        /// <summary>
        /// 消息结束id
        /// </summary>
        protected int _msgEndId;

        /// <summary>
        /// handle 处理的消息区间不能有交叉
        /// </summary>
        /// <param name="startId"></param>
        /// <param name="endId"></param>
        public MsgHandle(int startId, int endId)
        {
            _msgStartId = startId;
            _msgEndId = endId;
        }

        /// <summary>
        /// 是否为自己要处理的Id
        /// </summary>
        /// <param name="msgId"></param>
        /// <returns></returns>
        public bool IsSelfId(int msgId)
        {
            if(msgId >= _msgStartId && msgId <= _msgEndId)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 增加一个消息
        /// </summary>
        /// <param name="msg"></param>
        public virtual void AddMsg(Msg.MsgPacket msg)
        {
            ///默认异步处理消息，收到消息后直接处理
            ProcessMsg(msg);
        }

        /// <summary>
        /// 处理消息
        /// </summary>
        /// <param name="msg"></param>
        protected virtual void ProcessMsg(Msg.MsgPacket msg)
        {
        }

        /// <summary>
        /// 释放handle的资源
        /// </summary>
        public virtual void Release()
        { }
    }
}
